package algorithms2.sort;

import java.util.Arrays;

/**
 * @Author: DRevelation
 * @Date: 2021/9/10 17:29
 */
public class SelectSort {

    public static void main(String[] args) {
        int[] nums = {5, 3, 2, 1, 4};
        int[] sortedNums = selectSort(nums);
        System.out.println(Arrays.toString(sortedNums));
    }

    private static int[] selectSort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int minPos = i;
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] < nums[minPos]) {
                    minPos = j;
                }
            }
            Utils.swap(nums, minPos, i);
            System.out.println("第 " + (i + 1) + " 次排序结果是: " + Arrays.toString(nums));
        }
        return nums;
    }
}

